//引入扫描器
import Scan from './scan'
import nestToken from './nestToken';
export default function toToken(template) {

    let token = []
    let scan = new Scan(template)
    let word = ""
    while (scan.eco()) {
        word = scan.scanUtils('{{')
        word && token.push(['text', word])
        scan.scan("{{")
        word = scan.scanUtils('}}')
        if (word != "") {
            if (word[0] == "#") {
                token.push(['#', word.substring(1)])
            } else if (word[0] == "/") {
                token.push(['/', word.substring(1)])
            } else {
                token.push(['name', word])
            }
        }
        scan.scan("}}")
    }
    return nestToken(token)
}